package Runde8;

public class Hunter extends OneWayWorker {
	
	private static int counter = 0;
	private final int nr;
	private int huntingTrips;

	/**
	 * @precondition None of the arguments may be empty (null).
	 * @postcondition Creates a hunter.
	 */
	public Hunter(Storage target, int workingtime, int toGive, Company comp, int huntingTrips) {
		super(target, workingtime, toGive,  comp);
		this.huntingTrips = huntingTrips;
		this.nr = (counter++ % 2) + 1;
	}
	
	/**
	 * @postcondition Additionally to working, the number of remaining trips is decreased. Once this number reaches 0, the hunter stops calling super.work(). 
	 */
	public void run() {
		while (huntingTrips > 0 && super.comp.inOperation()) {
			super.work();
			huntingTrips--;
		}
		super.target.signOff();
	}

	/**
	 * @postcondition Returns a readable identification of the worker.
	 */
	public String toString() {
		return "Hunter " + nr;
	}
}
